package la.bbs558.util;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.extra.mail.MailUtil;
import la.bbs558.entity.dto.EmailMap;
import la.bbs558.exception.MsgException;

public class EmailUtils {
    private final static String EMAIL_HTML = ResourceUtil.readUtf8Str("templates/email.html");
    public static void send(EmailMap emailMap){
        if (Objs.isAnyInvalid(emailMap)) {
            throw new MsgException("缺少发送参数错误");
        }
        String html = Strings.format(EMAIL_HTML, BeanUtil.beanToMap(emailMap));
        MailUtil.send(emailMap.getToEmail() ,emailMap.getSubject(), html, true);
    }
}
